package com.os.pojo;

import com.os.pojo.physicalmemory.Frame;
import com.os.utils.ConfigUtils;
import lombok.Data;

import java.lang.reflect.Array;
import java.util.Arrays;

public class Memory<T> {

    /**
     * 全局页数组
     */
    public T[] memoryBlock;

    /**
     * 最大大小
     */
    public int maxSize;


    public Memory(int maxSize, Class<T> myClass,int frameSize) {
        this.maxSize = maxSize;

        // 获取存储块大小
//        int frameSize = (int) ConfigUtils.get(ConfigUtils.FRAME_SIZE);

        // 内存就分割成 maxSize/frameSize 个,上取整
        int size = maxSize / frameSize;
        if (maxSize % frameSize != 0) size++;

        this.memoryBlock = (T[]) Array.newInstance(myClass, size);

    }

    @Override
    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(String.format("maxSize:%d\n", this.maxSize));
        for (T item : memoryBlock) {
            stringBuilder.append(item).append("\n");
        }
        return stringBuilder.toString();
    }
}
